echo "Welcome to CloudDoor Installer."

echo "install apt-utils"
apt install apt-utils

sudo mkdir '/home/main'

echo "install libssl"
sudo apt-get install libssl-dev
cd /root/
echo "install libevent"
myPath="/root/libevent-2.0.21-stable.tar.gz"
echo "libevent file check"
if [ ! -f "$myPath" ]; then
   echo "libevent error python"
   wget https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz
fi
cd /root/
tar zxvf libevent-2.0.21-stable.tar.gz
cd libevent-2.0.21-stable
./configure -prefix=/usr
echo "install make libevent"
make
make install

ls -al /usr/lib | grep libevent

echo "install libffi-dev"
# sudo apt-get update
# sudo apt-get upgrade
# sudo apt-get dist-upgrade
sudo apt-get install python-dev python-setuptools python-pip python-smbus
# sudo apt-get install build-essential libncursesw5-dev libgdbm-dev libc6-dev
sudo apt-get install zlib1g-dev libsqlite3-dev
sudo apt-get install libssl-dev openssl
sudo apt-get install libffi-dev
sudo apt-get install lrzsz
# sudo apt-get install zlib*
cd /root
echo "install python"
myPath1="/root/Python-3.8.3.tgz"
if [ ! -f "$myPath1" ]; then
   echo "http error python"
   wget http://qprint.imgs.pandabg.cn/Python-3.8.3.tgz
fi

tar zxvf  Python-3.8.3.tgz -C ./
rm -rf /usr/bin/lsb_release

cd Python-3.8.3/
./configure --prefix=/usr/local/python3.8 --enable-shared
echo "install make Python"
make
make install

sudo apt-get install wheel

echo "install libpython3 copy"
cd /usr/local/python3.8/lib
cp libpython3.8.so.1.0 /usr/lib

cd /usr/bin/
rm -rf python3.bak
rm -rf pip3.bak
mv python3 python3.bak
mv pip3 pip3.bak

mv python python.bak
mv pip pip.bak

mkdir -p /root/.pip/
touch pip.conf
cat>/root/.pip/pip.conf<<EOF
[global]
index-url=http://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host=mirrors.aliyun.com
EOF

echo "install ln -s"
ln -s /usr/local/python3.8/bin/python3.8 /usr/bin/python3
ln -s /usr/local/python3.8/bin/pip3.8 /usr/bin/pip3

# echo "update pip"
# pip3 install --upgrade pip
# pip3 install --upgrade setuptools

# echo "install setuptools"
# pip3 install setuptools
# echo "install wheel"
# pip3 install wheel===0.36.2
# echo "install greenlet"
# pip3 install greenlet===1.1.2
# echo "install Pillow"
# pip3 install Pillow===8.4.0
# echo "install pyusb"
# pip3 install pyusb===1.2.1
# echo "install requests"
# pip3 install requests===2.26.0
# echo "install wheel"
# pip3 install wheel===0.36.2
# #echo "install numpy"
# #pip3 install numpy
# echo "install pyinstaller"
# pip3 install pyinstaller===4.2
# echo "install Cython "
# pip3 install Cython
# echo "install smbus2 "
# pip3 install smbus2


# #wget https://files.pythonhosted.org/packages/00/ca/58dd68fee42490be1c86c9e912fc9ad0bf44c72edd882397ad11c21fbecb/pyinstaller-4.7.tar.gz
# #tar -zxvf pyinstaller-4.7.tar.gz
# #

# echo "install pyinstaller mv"
# cp /usr/local/python3.8/bin/pyinstaller /usr/bin/pyinstaller

# echo "install pyinstaller-hooks-contrib "
# pip3 install pyinstaller-hooks-contrib===2021.4

# echo "install zope.interface "
# pip3 install zope.interface===5.4.0
# echo "install zope.event	4.5.0	 "
# pip3 install zope.event===4.5.0
# echo "install mysql-connector	2.2.9	 "
# pip3 install mysql-connector===2.2.9


# # cd /root
# # echo "install gevent"
# # #wget https://files.pythonhosted.org/packages/c8/18/631398e45c109987f2d8e57f3adda161cc5ff2bd8738ca830c3a2dd41a85/gevent-21.12.0.tar.gz
# # sudo  apt-get install libmysqlclient-dev python3-dev

# # myPath2="/root/gevent-21.1.2.tar.gz"
# # if [ ! -f "$myPath2" ]; then
# #   wget https://files.pythonhosted.org/packages/0b/50/1b1175ea3a269b5fa3f0f7fed11149888180695bef5fbf568adbb196efaf/gevent-21.1.2.tar.gz
# # fi
# # tar -zxvf gevent-21.1.2.tar.gz
# # cd gevent-21.1.2
# # sudo python3 setup.py install
# # echo "install websocket"
# # pip3 install websocket===0.2.1
# # echo "install websocket-client"
# # pip3 install websocket-client===1.2.3
# # echo "install socketutils"
# # pip3 install socketutils===0.4.0
# # echo "install pyserial"
# # pip3 install pyserial===3.5
# echo "install paho-mqtt"
# pip3 install paho-mqtt
# echo "install pydub"
# pip3 install pydub===0.25.1

# cd /root
# git clone https://gitee.com/ahnu119/RPi.GPIO_NP.git
# cd RPi.GPIO_NP
# python setup.py install                 
